//
//  PatcherView.m
//  ImageReplacer
//
//  Created by Tyler Powell on 5/6/12.
//  Copyright (c) 2012 Georgia Institute of Technology. All rights reserved.
//

#import "EnButtonView.h"

@implementation EnButtonView
@synthesize writer;
-(IBAction)setSelectedImage:(id)sender{
    //NSLog(@"ENTERED");
    id* selection = [sender selectedRowIndexes];
    //NSLog(@"Count:%d", [selection count]);
    if ([selection count]==0) {
        [self setImage:nil];
        return;
    }
    selectedRow = [selection firstIndex];
    NSString* imagePath = [[writer enbuttons] objectAtIndex:selectedRow];
    //NSLog(imagePath);
    imagePath = [@"file://" stringByAppendingString:imagePath];
    imagePath = [imagePath stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
    
    NSURL* imageURL = [NSURL URLWithString:imagePath];
    NSData* imageData = [imageURL resourceDataUsingCache:NO];
    NSImage* imageFromBundle = [[NSImage alloc] initWithData:imageData];
    
    //[self setImageScaling:NSImageScaleNone];
    //[self setImageAlignment:NSImageAlignTopLeft];
    if(imageFromBundle){
        [self setImage:imageFromBundle];
        //NSLog(@"Image set");
    }
    [imageFromBundle release];
    //NSLog(@"GotHere");
    //[self setNeedsDisplay:YES];
    [self display];
    
}

@end
